<template>
  <div class="container">
    <text class="big-title">示例</text>
    <div>
      <div ref="animBox" class="box"></div>
      <div class="line"></div>
      <div class="menu-container">
        <div class="menu-btn" @click="startAnim(0)">
          <text class="menu-btn-text">旋转</text>
        </div>
        <div class="menu-btn" @click="startAnim(1)">
          <text class="menu-btn-text">缩放</text>
        </div>
        <div class="menu-btn" @click="startAnim(2)">
          <text class="menu-btn-text">位移</text>
        </div>
        <div class="menu-btn" @click="startAnim(3)">
          <text class="menu-btn-text">透明度</text>
        </div>
        <div class="menu-btn" @click="startAnim(4)">
          <text class="menu-btn-text">综合</text>
        </div>
      </div>
    </div>
    <text class="big-title">文档</text>
    <div class="button" @click="showDoc"><text class="btn-text">点击查看文档</text></div>
  </div>
</template>

<style scoped>
.container {
  padding: 10px;
}
.big-title {
  color: black;
  font-size: 50px;
  font-weight: bold;
  margin-bottom: 20px;
  margin-top: 20px;
}
.box {
  width: 300px;
  height: 300px;
  background-color: #6699FF;
}
.line {
  height: 1.8px;
  margin-top: 10px;
  margin-bottom: 10px;
  background-color: #ECECEC;
}
.menu-container {
  flex-direction: row;
  align-items: center;
  justify-content: center;
}
.menu-btn {
  border-radius: 6px;
  border-color: black;
  border-width: 2px;
  padding-left: 25px;
  padding-right: 25px;
  padding-top: 15px;
  margin-left: 8px;
  margin-right: 8px;
  padding-bottom: 15px;
  background-color: transparent;
}
.menu-btn:active {
  background-color: #ECECEC;
}
.menu-btn-text {
  font-size: 28px;
}
.button {
  height: 60px;
  justify-content: center;
  opacity: 1.0;
}
.button:active {
  opacity: 0.6;
}
.btn-text {
  font-size: 30px;
  color: blue;
}
</style>

<script>
  let modal = weex.requireModule('modal');
  let anim = weex.requireModule('animation');
  let navigator = weex.requireModule('navigator');
  import utils from '../utils.js';
  let rotateAnim = {
    styles: {
      transform: 'rotate(120deg)',
      opacity: '1.0'
    },
    timingFunction: 'linear',
    duration: 800,
  };
  let scaleAnim = {
    styles: {
      transform: 'scale(0.8)',
      opacity: '1.0'
    },
    timingFunction: 'linear',
    duration: 500,
  };
  let transformAnim = {
    styles: {
      transform: 'translate(200px, 0px)',
      opacity: '1.0'
    },
    timingFunction: 'linear',
    duration: 500,
  };
  let alphaAnim = {
    styles: {
      opacity: '0.2'
    },
    timingFunction: 'linear',
    duration: 500,
  };
  let combineAnim = {
    styles: {
      opacity: '0.2',
      transform: 'scale(0.8) translate(200px, 0px) rotate(120deg)'
    },
    timingFunction: 'linear',
    duration: 500,
  };
  export default {
    data: {
    },
    methods: {
      startAnim(index) {
        let animObj;
        switch (index) {
          case 0:
            animObj = rotateAnim;
            break;
          case 1:
            animObj = scaleAnim;
            break;
          case 2:
            animObj = transformAnim;
            break;
          case 3:
            animObj = alphaAnim;
            break;
          case 4:
            animObj = combineAnim;
        }
        anim.transition(this.$refs.animBox, animObj, ()=>{
          modal.toast({
            message: 'animation finished!',
            duration: 1
          })
        })
      },
      showDoc() {
        navigator.push({
          url: utils.getDocDetailUrl(weex.config.bundleUrl),
          animated: true
        });
      }
    }
  }
</script>
